package com.yc.cloud.admin.controller;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.common.orm.CommonPage;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.admin.dto.request.AlgModelVersionCreateReqDTO;
import com.yc.cloud.admin.dto.request.AlgModelVersionQueryReqDTO;
import com.yc.cloud.admin.dto.request.AlgModelVersionUpdateReqDTO;
import com.yc.cloud.admin.vo.AlgModelVersionVo;
import com.yc.cloud.admin.service.AlgModelVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;

/**
 * <p>
 * 算法模型版本表 前端控制器
 * </p>
 *
 * @author kinggu
 * @since 2025-07-11
 */
@RestController
@Api(tags = "算法模型版本表")
@RequestMapping("/alg-model-versions")
public class AlgModelVersionController {

    @Resource
    private AlgModelVersionService algModelVersionService;

    @ApiOperation("创建算法模型版本表")
    @PostMapping
    public ResponseResult<Boolean> create(@Validated @RequestBody AlgModelVersionCreateReqDTO createReqDTO) {
        return ResponseResult.success(algModelVersionService.create(createReqDTO));
    }

    @ApiOperation("更新算法模型版本表")
    @PutMapping("/{id}")
    public ResponseResult<Boolean> update(@PathVariable("id") Long id,
            @Validated @RequestBody AlgModelVersionUpdateReqDTO updateReqDTO) {
        updateReqDTO.setId(id);
        return ResponseResult.success(algModelVersionService.update(updateReqDTO));
    }

    @ApiOperation("发布模型版本")
    @PutMapping("/{id}/publish")
    public ResponseResult<Boolean> publish(@PathVariable("id") Long id) {
        boolean result = algModelVersionService.publish(id);
        return result ? ResponseResult.success() : ResponseResult.failed();
    }

    @ApiOperation("取消发布模型版本")
    @PutMapping("/{id}/unpublish")
    public ResponseResult<Boolean> unpublish(@PathVariable("id") Long id) {
        boolean result = algModelVersionService.unpublish(id);
        return result ? ResponseResult.success() : ResponseResult.failed();
    }

    @ApiOperation("删除算法模型版本表")
    @DeleteMapping("/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {
        boolean result = algModelVersionService.delete(id);
        return result ? ResponseResult.success() : ResponseResult.failed();
    }

    @ApiOperation("获取算法模型版本表详情")
    @GetMapping("/{id}")
    public ResponseResult<AlgModelVersionVo> getById(@PathVariable("id") Long id) {
        return ResponseResult.success(algModelVersionService.getVOById(id));
    }

    @ApiOperation("分页查询算法模型版本表")
    @GetMapping
    public ResponseResult<CommonPage<AlgModelVersionVo>> list(@Validated AlgModelVersionQueryReqDTO queryReqDTO) {
        return ResponseResult.success(algModelVersionService.list(queryReqDTO));
    }
}
